import request from '@/utils/request'

export function getArticleList (params) {
  return request({
    method: 'GET',
    url: '/app/v1_1/articles',
    params: params
  })
}

export function getArticleById (articleId) { // articleId传过来的是一个对象
  console.log(articleId)
  console.log(articleId.toString())
  return request({
    method: 'GET',
    // 下面这一行本质是字符串拼接的ES6写法,相当于是把articleId当成字符串来用,隐式进行toString处理
    url: `/app/v1_0/articles/${articleId}`
  })
}

// 添加收藏
// target --> 文章的id
export function addCollection (target) {
  return request({
    method: 'POST',
    url: '/app/v1_0/article/collections',
    data: {
      target
    }
  })
}
// 取消收藏
// target --> 文章的id
export function deleteCollection (target) {
  return request({
    method: 'DELETE',
    url: `/app/v1_0/article/collections/${target}`
  })
}

// 取消点赞
export function deleteLike (target) {
  return request({
    method: 'DELETE',
    url: `/app/v1_0/article/likings/${target}`
  })
}

// 点赞
export function like (target) {
  return request({
    method: 'POST',
    url: '/app/v1_0/article/likings',
    data: {
      target
    }
  })
}
